package org.xx.armory.swing.builders;

import org.xx.armory.objectparser.LineInfo;
import org.xx.armory.swing.components.BorderType;

import javax.swing.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

public class BoxLayoutModel
        extends AbstractLayoutModel
        implements ContainerModel {
    private final ModelAlignment horizontalAlignment;
    private final ModelAlignment verticalAlignment;
    private final int axis;
    private final List<ComponentModel> children;

    protected BoxLayoutModel(
            LineInfo lineInfo,
            String name,
            boolean visible,
            String title,
            BorderType border,
            ModelAlignment horizontalAlignment,
            ModelAlignment verticalAlignment,
            int axis,
            Collection<? extends ComponentModel> children
    ) {
        super(lineInfo, name, visible, title, border);

        this.horizontalAlignment = horizontalAlignment;
        this.verticalAlignment = verticalAlignment;
        if (axis != BoxLayout.X_AXIS && axis != BoxLayout.Y_AXIS) {
            throw new IllegalArgumentException("illegal axis: " + axis);
        }
        this.axis = axis;
        this.children = children != null ? new ArrayList<>(children) : Collections.emptyList();
    }

    public final ModelAlignment getHorizontalAlignment() {
        return this.horizontalAlignment;
    }

    public final ModelAlignment getVerticalAlignment() {
        return this.verticalAlignment;
    }

    public final int getAxis() {
        return this.axis;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public final List<ComponentModel> getChildren() {
        return this.children;
    }
}
